//
//  MagazineTableViewCell.m
//  B_WatchHome
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 DHF. All rights reserved.
//

#import "MagazineTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@implementation MagazineTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    // 展示图片
    self.leftImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.leftImageView];
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.and.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(80, 90));
        
    }];
    
    // 标题
    self.headLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.headLabel];
    [self.headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(-15);
        make.left.mas_equalTo(self.leftImageView.mas_right).offset(0);
        self.headLabel.font = [UIFont boldSystemFontOfSize:14];
    }];
    
    
    self.midLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.midLabel];
    [self.midLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.headLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(self.leftImageView.mas_right).offset(10);
        make.right.mas_equalTo(-75);
        self.midLabel.font = [UIFont boldSystemFontOfSize:11];
        
    }];
    
    self.footLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.footLabel];
    [self.footLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.midLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(self.leftImageView.mas_right).offset(10);
        make.right.mas_equalTo(-5);
        self.footLabel.font = [UIFont boldSystemFontOfSize:13];
        self.footLabel.numberOfLines = 0;
      
    }];

}

- (void)setModel:(MagazineModel *)model
{
    if (_model != model) {
        _model = model;
    }
    
    self.headLabel.text = self.model.title;
    self.midLabel.text = self.model.pubdate;
    self.footLabel.text = self.model.summary;
    
    NSURL *url = [NSURL URLWithString:self.model.cover_thumb];
    
    [self.leftImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1.jpg"]];
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
